﻿using System;
using System.Collections.Generic;

namespace QDT.Core.Deals
{
    public class Credit : Entity
    {
        public Credit()
        {
            CreateTime = DateTime.Now;
            TransferMoney = 0;
            RepayEarning = 0;
            RepayPrincipal = 0;
            CurrentStage = 0;
            IsRepay = false;
            IsAssign = false;
        }

        /// <summary>
        /// 项目的ID
        /// </summary>
        public int  ProjectID { get; set; }

        /// <summary>
        /// 债权ID
        /// </summary>
        public int UserID { get; set; }

        /// <summary>
        /// 债权人的帐号
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 持有债权金额
        /// </summary>
        public decimal Money { get; set; }

        /// <summary>
        /// 购买债权金额
        /// </summary>
        public decimal BuyMoney { get; set; }

        /// <summary>
        /// 已转让债权金额
        /// </summary>
        public decimal TransferMoney { get; set; }

        /// <summary>
        /// 已回收利息
        /// </summary>
        public decimal RepayEarning { get; set; }

        /// <summary>
        /// 待回收利息
        /// </summary>
        public decimal WaitRepayEarning { get; set; }

        /// <summary>
        /// 已回收本金
        /// </summary>
        public decimal RepayPrincipal { get; set; }

        /// <summary>
        /// 待回收本金
        /// </summary>
        public decimal WaitRepayPrincipal { get; set; }

        /// <summary>
        /// 已回收总金额
        /// </summary>
        public decimal RepayMoney{get { return RepayEarning + RepayPrincipal; }}

        /// <summary>
        /// 待回收总金额
        /// </summary>
        public decimal WaitRepayMoney{get { return WaitRepayEarning + WaitRepayPrincipal; }}

        /// <summary>
        /// 投资时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 债权也返回几期收益
        /// </summary>
        public int CurrentStage { get; set; }

        /// <summary>
        /// 债权总的收益周期
        /// </summary>
        public int TotalStage { get; set; }


        /// <summary>
        /// 上次还款时间
        /// </summary>
        public DateTime? LastRepayTime { get; set; }

        /// <summary>
        /// 下次还款时间
        /// </summary>
        public DateTime? NextRepayTime { get; set; }

        /// <summary>
        /// 是否偿还
        /// </summary>
        public bool IsRepay { get; set; }

        /// <summary>
        /// 偿还记录
        /// </summary>
        public virtual ICollection<CreditRepayment> Repayments { get; private set; }

        /// <summary>
        /// 是否有效
        /// </summary>
        public bool IsEffect {
            get {
                if (Money > 0) {
                    return true;
                }
                return false;
            }
        }

        public int InnerType { get; set; }

        /// <summary>
        /// 债权类型
        /// </summary>
        public InvestType Type
        {
            get { return (InvestType)InnerType; }
            set { InnerType = (int)value; }
        }

        public int InnerStatus { get; set; }

        /// <summary>
        /// 债券的状态
        /// </summary>
        public CreditStatus Status {
            get { return (CreditStatus) InnerStatus; }
            set { InnerStatus = (int) value; }
        }

        /// <summary>
        /// 购买的转让债权ID，如果是直投，ID为0
        /// </summary>
        public int AssignmentID { get; set; }

        /// <summary>
        /// 是否转让
        /// </summary>
        public bool IsAssign { get; set; }

        /// <summary>
        /// 是否自动投标
        /// </summary>
        public bool IsAuto { get; set; }

        /// <summary>
        /// 是否自动投标
        /// </summary>
        public bool IsEasy { get; set; }

        /// <summary>
        /// 客户端
        /// </summary>
        public int Client { get; set; }

    }
}
